function ImportAllScripts(url) {
    IncludeJavaScript(url + "Scripts/MicrosoftMvcAjax.js");
    IncludeJavaScript(url + "Scripts/MicrosoftAjax.js");
    IncludeJavaScript(url + "Scripts/jquery.validate.js");
    IncludeJavaScript(url + "Scripts/jquery.validate.min.js");
    IncludeJavaScript(url + "Scripts/jquery-1.5.1.min.js");
    IncludeJavaScript(url + "Scripts/jquery.unobtrusive-ajax.min.js");
    IncludeJavaScript(url + "Scripts/Layout.js");
//    IncludeJavaScript(url + "Scripts/jquery.cookies.min.js");
}

function IncludeJavaScript(jsFile) {
    document.write('<script type="text/javascript" src="'
    + jsFile + '"></scr' + 'ipt>');
}

function setCookie(cookieName, value, time) {
    jaaulde.utils.cookies.set(cookieName, value, { expires: time });

}

function viewDropContent(id) {
    if ($("#" + id).size()) {
        var temp = false;
        if (id.toLowerCase().indexOf('day') >= 0) {
            temp = is_viewDay;
            is_viewDay = !temp;
        }
        else if (id.toLowerCase().indexOf('month') >= 0) {
            temp = is_viewMonth;
            is_viewMonth = !temp;
        }
        else if (id.toLowerCase().indexOf('year') >= 0) {
            temp = is_viewYear;
            is_viewYear = !temp;
        }
        else {
            temp = is_viewGender;
            is_viewGender = !temp;
        }

        if (!temp)
            $("#" + id).show()
        else
            $("#" + id).hide()
    }
}

function SethideDropContent(id, objInput) {
    if ($("#" + id).size() && $("#" + objInput).size()) {
        $("#" + id + " div").click(function() {
            $("#" + objInput).val($(this).text())
            $("#" + id).hide()
        });
    }
}

var autoDetect_scroll_onMobile = null;

function getMoreQuestions() {
    var isMobile = navigator.userAgent.toLowerCase().match(/(iphone|ipod|ipad|android|blackberry)/);
    var isIOS = ((/iphone|ipad/gi).test(navigator.appVersion));
    if (isIOS || isMobile) {
        autoDetect_scroll_onMobile = window.setInterval(autoDetectScrollTop_onMobile, 1000);
        //        $("#bgtest").text("mobile");
    }
    else {
        $(window).scroll(function () {
            var scrolltop = $(window).scrollTop();
            var test_postion = $("#tester_div").position().top;
//            alert($("#bgQuestionGroup_onHome").height() + "-" + (scrolltop + test_postion));
            //            $("#bgtest").text(isgetNext);
            if (isgetNext && test_postion + scrolltop >= (($("#bgQuestionGroup_onHome").height() + 300) * 2 / 3)) {

                //                $("#bgtest").html("submit");
                isSubmitingForm = true;
                $("#frmUpdatePic").submit();
                isgetNext = false;
                $("#bgQuestionGroup_onHome").append('<div id="bgwaitingLoadmore" class="bgwaitingLoadmore">loading more...</div>');
            }
            else {
                if ($("#bgwaitingLoadmore").size())
                    $("#bgwaitingLoadmore").remove();
            }
        });
    }
}

function removeWaitingDiv() {
    if ($("#bgwaitingLoadmore").size())
        $("#bgwaitingLoadmore").remove();
}

function autoDetectScrollTop_onMobile() {
    scrolltop = $(window).scrollTop();
    var test_postion = $("#tester_div").position().top;
    if (isgetNext && test_postion + scrolltop >= (($("#bgQuestionGroup_onHome").height() + 244) * 2 / 3)) {
        $("#frmUpdatePic").submit();
        isgetNext = false;
        $("#bgQuestionGroup_onHome").append('<div id="bgwaitingLoadmore" class="bgwaitingLoadmore">loading more...</div>')
        window.clearInterval(autoDetect_scroll_onMobile);
    }
    else {
        if ($("#bgwaitingLoadmore").size())
            $("#bgwaitingLoadmore").remove();
    }
}

function changePicItem2Parent(container, tempId) {
    try {
        
        //Run some code here
        if ($(tempId).size() && container != null) {
            var star = 1;
            var end = 3;
            
            var temp_count = 0;
            var temp_height = 0;
            var con = null;
            var cur_index = star;

            if (star == end) {
                con = $("#" + container + star);
                con.append($(tempId).html());
                resetMouseEvent(con.last());
                
                return true;
            }
            for (var i = star; i <= end; i++) {
                var count = $("#" + container + i + ' .bgpic_item');
                var item = $("#" + container + i);
                if (count.length <= 0) {
                    con = $("#" + container + i);
                    con.append($(tempId).html());
                    resetMouseEvent(con.last());
                    return true;
                }

                if (temp_count <= 0) {
                    temp_count = count.length;
                    temp_height = item.height();
                    cur_index = i;
                }
                else {
                    if (temp_height != item.height()) {
                        cur_index = (temp_height > item.height() + 70 ? i : cur_index);
                        temp_height = (temp_height > item.height() + 70 ? item.height() : temp_height);
                    }
                    else {
                        if (temp_count != count.length) {
                            cur_index = (temp_count > count.length ? i : cur_index);
                            temp_count = (temp_count > count.length ? count.length : temp_count);
                        }
                    }

                    if (i == end) {
                        con = $("#" + container + (cur_index));
                        con.append($(tempId).html());
                        resetMouseEvent(con.last());
                        return true;
                    }
                }

            }
        }
    }
    catch (err) {
        //Handle errors here
    }
}

function updaterAfterGetMoreCompleted(tempId, isGetNextPage, pageIndex) {
    //clear content of temp updated area
    if ($(tempId).size())
        $(tempId).html(" ");
    //remove waiting div
    removeWaitingDiv();
    //update pageIndex
    if ($("#PageIndex").size() && pageIndex != "null")
        $("#PageIndex").val(pageIndex);

    var isMobile = navigator.userAgent.toLowerCase().match(/(iphone|ipod|ipad|android|blackberry)/);
    var isIOS = ((/iphone|ipad/gi).test(navigator.appVersion));
    if (isIOS || isMobile) {
        autoDetect_scroll_onMobile = window.setInterval(autoDetectScrollTop_onMobile, 1000);
    }

    isgetNext = (isGetNextPage != null ? isGetNextPage : false);
}
var temp_isgetNext = true;
function stopLoadPic() {
    isgetDetail = true;
    temp_isgetNext = isgetNext;
    if (isgetNext)
        isgetNext = false;

    return true;
}

function loadNextPic() {
    isgetNext = true;
    return true;
}
